<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>苍穹外卖笔记day1 | 小潘的个人博客</title><meta name="author" content="John Doe"><meta name="copyright" content="John Doe"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="苍穹外卖-day011.五大技术选型1). 用户层 本项目中在构建系统管理后台的前端页面，我们会用到H5、Vue.js、ElementUI、apache echarts(展示图表)等技术。而在构建移动端应用时，我们会使用到微信小程序。 2). 网关层 Nginx是一个服务器，主要用来作为Http服务器，部署静态资源，访问性能高。在Nginx中还有两个比较重要的作用： 反向代理和负载均衡， 在进行项">
<meta property="og:type" content="article">
<meta property="og:title" content="苍穹外卖笔记day1">
<meta property="og:url" content="https://t0wolf.gitee.io/xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/index.html">
<meta property="og:site_name" content="小潘的个人博客">
<meta property="og:description" content="苍穹外卖-day011.五大技术选型1). 用户层 本项目中在构建系统管理后台的前端页面，我们会用到H5、Vue.js、ElementUI、apache echarts(展示图表)等技术。而在构建移动端应用时，我们会使用到微信小程序。 2). 网关层 Nginx是一个服务器，主要用来作为Http服务器，部署静态资源，访问性能高。在Nginx中还有两个比较重要的作用： 反向代理和负载均衡， 在进行项">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-10-31T09:13:57.000Z">
<meta property="article:modified_time" content="2023-10-31T11:56:07.624Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="./img/favicon.png"><link rel="canonical" href="https://t0wolf.gitee.io/xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="./css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: './',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy Successful',
    error: 'Copy Error',
    noSupport: 'Browser Not Supported'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just now',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: 'Load More'
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '苍穹外卖笔记day1',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-10-31 19:56:07'
}</script><script>(win=>{
      win.saveToLocal = {
        set: (key, value, ttl) => {
          if (ttl === 0) return
          const now = Date.now()
          const expiry = now + ttl * 86400000
          const item = {
            value,
            expiry
          }
          localStorage.setItem(key, JSON.stringify(item))
        },
      
        get: key => {
          const itemStr = localStorage.getItem(key)
      
          if (!itemStr) {
            return undefined
          }
          const item = JSON.parse(itemStr)
          const now = Date.now()
      
          if (now > item.expiry) {
            localStorage.removeItem(key)
            return undefined
          }
          return item.value
        }
      }
    
      win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        script.onerror = reject
        script.onload = script.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          script.onload = script.onreadystatechange = null
          resolve()
        }

        Object.keys(attr).forEach(key => {
          script.setAttribute(key, attr[key])
        })

        document.head.appendChild(script)
      })
    
      win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onerror = reject
        link.onload = link.onreadystatechange = function() {
          const loadState = this.readyState
          if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
          link.onload = link.onreadystatechange = null
          resolve()
        }
        document.head.appendChild(link)
      })
    
      win.activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
        if (t === 'dark') activateDarkMode()
        else if (t === 'light') activateLightMode()
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
      const detectApple = () => {
        if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
          document.documentElement.classList.add('apple')
        }
      }
      detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"><link rel="alternate" href="./atom.xml" title="小潘的个人博客" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="./archives/"><div class="headline">Articles</div><div class="length-num">10</div></a><a href="./tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="./categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><hr class="custom-hr"/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="./" title="小潘的个人博客"><span class="site-name">小潘的个人博客</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">苍穹外卖笔记day1</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-10-31T09:13:57.000Z" title="Created 2023-10-31 17:13:57">2023-10-31</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-10-31T11:56:07.624Z" title="Updated 2023-10-31 19:56:07">2023-10-31</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="苍穹外卖笔记day1"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post Views:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="苍穹外卖-day01"><a href="#苍穹外卖-day01" class="headerlink" title="苍穹外卖-day01"></a>苍穹外卖-day01</h1><h2 id="1-五大技术选型"><a href="#1-五大技术选型" class="headerlink" title="1.五大技术选型"></a>1.五大技术选型</h2><p><strong>1). 用户层</strong></p>
<p>本项目中在构建系统管理后台的前端页面，我们会用到H5、Vue.js、ElementUI、apache echarts(展示图表)等技术。而在构建移动端应用时，我们会使用到微信小程序。</p>
<p><strong>2). 网关层</strong></p>
<p>Nginx是一个服务器，主要用来作为Http服务器，部署静态资源，访问性能高。在Nginx中还有两个比较重要的作用： 反向代理和负载均衡， 在进行项目部署时，要实现Tomcat的负载均衡，就可以通过Nginx来实现。</p>
<p><strong>3). 应用层</strong></p>
<p>SpringBoot： 快速构建Spring项目, 采用 “约定优于配置” 的思想, 简化Spring项目的配置开发。</p>
<p>SpringMVC：SpringMVC是spring框架的一个模块，springmvc和spring无需通过中间整合层进行整合，可以无缝集成。</p>
<p>Spring Task:  由Spring提供的定时任务框架。</p>
<p>httpclient:  主要实现了对http请求的发送。</p>
<p>Spring Cache:  由Spring提供的数据缓存框架</p>
<p>JWT:  用于对应用程序上的用户进行身份验证的标记。</p>
<p>阿里云OSS:  对象存储服务，在项目中主要存储文件，如图片等。</p>
<p>Swagger： 可以自动的帮助开发人员生成接口文档，并对接口进行测试。</p>
<p>POI:  封装了对Excel表格的常用操作。</p>
<p>WebSocket: 一种通信网络协议，使客户端和服务器之间的数据交换更加简单，用于项目的来单、催单功能实现。</p>
<p><strong>4). 数据层</strong></p>
<p>MySQL： 关系型数据库, 本项目的核心业务数据都会采用MySQL进行存储。</p>
<p>Redis： 基于key-value格式存储的内存数据库, 访问速度快, 经常使用它做缓存。</p>
<p>Mybatis： 本项目持久层将会使用Mybatis开发。</p>
<p>pagehelper:  分页插件。</p>
<p>spring data redis:  简化java代码操作Redis的API。</p>
<p><strong>5). 工具</strong></p>
<p>git: 版本控制工具, 在团队协作中, 使用该工具对项目中的代码进行管理。</p>
<p>maven: 项目构建工具。</p>
<p>junit：单元测试工具，开发人员功能实现完毕后，需要通过junit对功能进行单元测试。</p>
<p>postman:  接口测工具，模拟用户发起的各类HTTP请求，获取对应的响应结果。</p>
<h2 id="2-开发环境搭建"><a href="#2-开发环境搭建" class="headerlink" title="2. 开发环境搭建"></a>2. 开发环境搭建</h2><h3 id="1-前端环境搭建"><a href="#1-前端环境搭建" class="headerlink" title="1. 前端环境搭建"></a>1. 前端环境搭建</h3><p>1). 前端工程基于 nginx </p>
<p>从资料中找到前端运行环境的nginx，移动到<strong>非中文目录</strong>下。</p>
<p><a target="_blank" rel="noopener" href="http://localhost/">http://localhost:80</a></p>
<h3 id="2-后端环境搭建"><a href="#2-后端环境搭建" class="headerlink" title="2.后端环境搭建"></a>2.后端环境搭建</h3><p>对工程的每个模块作用说明：</p>
<table>
<thead>
<tr>
<th><strong>序号</strong></th>
<th><strong>名称</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>1</td>
<td>sky-take-out</td>
<td>maven父工程，统一管理依赖版本，聚合其他子模块</td>
</tr>
<tr>
<td>2</td>
<td>sky-common</td>
<td>子模块，存放公共类，例如：工具类、常量类、异常类等</td>
</tr>
<tr>
<td>3</td>
<td>sky-pojo</td>
<td>子模块，存放实体类、VO、DTO等</td>
</tr>
<tr>
<td>4</td>
<td>sky-server</td>
<td>子模块，后端服务，存放配置文件、Controller、Service、Mapper等</td>
</tr>
</tbody></table>
<h3 id="3-数据库搭建"><a href="#3-数据库搭建" class="headerlink" title="3.数据库搭建"></a>3.数据库搭建</h3><h3 id="4-前后端联调"><a href="#4-前后端联调" class="headerlink" title="4. 前后端联调"></a>4. 前后端联调</h3><p><img src="./xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/image-20231031190353734.png" alt="image-20231031190353734"></p>
<p><code>getBytes</code>的方法，该方法返回一个字节数组，该数组表示该字符串的字节表示形式。这个方法通常用于将字符串转换为字节数组，以便在网络传输或其他需要字节数据的情况下使用。例如，在将文件从服务器传输到客户端时，通常需要将文件转换为字节数组。</p>
<h2 id="3-nginx"><a href="#3-nginx" class="headerlink" title="3.nginx"></a>3.nginx</h2><p>nginx反向代理和负载均衡</p>
<p><strong>前端发送的请求，是如何请求到后端服务的？</strong></p>
<p>前端请求地址：<a target="_blank" rel="noopener" href="http://localhost/api/employee/login">http://localhost/api/employee/login</a></p>
<p>后端接口地址：<a target="_blank" rel="noopener" href="http://localhost:8080/admin/employee/login">http://localhost:8080/admin/employee/login</a></p>
<p>很明显，两个地址不一致，那是如何请求到后端服务的呢？</p>
<h3 id="1-nginx反向代理"><a href="#1-nginx反向代理" class="headerlink" title="1.nginx反向代理"></a>1.nginx反向代理</h3><p><strong>nginx 反向代理</strong>，就是将前端发送的动态请求由 nginx 转发到后端服务器</p>
<p>????为什么不直接通过浏览器直接请求后台服务端，需要通过nginx反向代理呢？</p>
<p><strong>nginx 反向代理的好处：</strong></p>
<ul>
<li><p>提高访问速度</p>
<p>因为nginx本身可以进行缓存，如果访问的同一接口，并且做了数据缓存，nginx就直接可把数据返回，不需要真正地访问服务端，从而提高访问速度。</p>
</li>
<li><p>进行负载均衡</p>
<p>所谓负载均衡,就是把大量的请求按照我们指定的方式均衡的分配给集群中的每台服务器。</p>
</li>
<li><p>保证后端服务安全</p>
<p>因为一般后台服务地址不会暴露，所以使用浏览器不能直接访问，可以把nginx作为请求访问的入口，请求到达nginx后转发到具体的服务中，从而保证后端服务的安全。</p>
<p><img src="./xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/image-20231031193240119.png" alt="image-20231031193240119"></p>
<h3 id="2-nginx-负载均衡策略"><a href="#2-nginx-负载均衡策略" class="headerlink" title="2.nginx 负载均衡策略"></a>2.nginx 负载均衡策略</h3><table>
<thead>
<tr>
<th><strong>名称</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>轮询</td>
<td>默认方式</td>
</tr>
<tr>
<td>weight</td>
<td>权重方式，默认为1，权重越高，被分配的客户端请求就越多</td>
</tr>
<tr>
<td>ip_hash</td>
<td>依据ip分配方式，这样每个访客可以固定访问一个后端服务</td>
</tr>
<tr>
<td>least_conn</td>
<td>依据最少连接方式，把请求优先分配给连接数少的后端服务</td>
</tr>
<tr>
<td>url_hash</td>
<td>依据url分配方式，这样相同的url会被分配到同一个后端服务</td>
</tr>
<tr>
<td>fair</td>
<td>依据响应时间方式，响应时间短的服务将会被优先分配</td>
</tr>
</tbody></table>
</li>
</ul>
<p><strong>weight:</strong></p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">upstream</span> webservers&#123;</span><br><span class="line">    <span class="attribute">server</span> <span class="number">192.168.100.128:8080</span> weight=<span class="number">90</span>;</span><br><span class="line">    <span class="attribute">server</span> <span class="number">192.168.100.129:8080</span> weight=<span class="number">10</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>等等 都是相同的格式</p>
<h2 id="4-完善登录功能"><a href="#4-完善登录功能" class="headerlink" title="4.完善登录功能"></a>4.完善登录功能</h2><p>使用MD5加密方式对明文密码加密</p>
<p><strong>实现步骤：</strong></p>
<ol>
<li><p>修改数据库中明文密码，改为MD5加密后的密文</p>
<p>打开employee表，修改密码</p>
<p><img src="./xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/image-20221107161446710.png" alt="image-20221107161446710"></p>
</li>
<li><p>修改Java代码，前端提交的密码进行MD5加密后再跟数据库中密码比对</p>
<p>打开EmployeeServiceImpl.java，修改比对密码</p>
<p>这是来自EmployeeService 中的login 方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">password = DigestUtils.md5DigestAsHex(password.getBytes());</span><br><span class="line">        <span class="keyword">if</span> (!password.equals(employee.getPassword())) &#123;</span><br><span class="line">            <span class="comment">//密码错误</span></span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">PasswordErrorException</span>(MessageConstant.PASSWORD_ERROR);</span><br><span class="line">        &#125;</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="5-导入接口文档"><a href="#5-导入接口文档" class="headerlink" title="5. 导入接口文档"></a>5. 导入接口文档</h2><p>1.导入到YApi平台 <a target="_blank" rel="noopener" href="https://yapi.pro/group/154876">YApi Pro-高效、易用、功能强大的可视化接口管理平台</a></p>
<p>2.Swagger</p>
<p>knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,前身是swagger-bootstrap-ui,取名kni4j是希望它能像一把匕首一样小巧,轻量,并且功能强悍!</p>
<h3 id="使用步骤"><a href="#使用步骤" class="headerlink" title="使用步骤"></a>使用步骤</h3><ol>
<li><p>导入 knife4j 的maven坐标</p>
<p>在pom.xml中添加依赖</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>com.github.xiaoymin<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">   <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>knife4j-spring-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>在配置类中加入 knife4j 相关配置</p>
<p>WebMvcConfiguration.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 通过knife4j生成接口文档</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="keyword">public</span> Docket <span class="title function_">docket</span><span class="params">()</span> &#123;</span><br><span class="line">        <span class="type">ApiInfo</span> <span class="variable">apiInfo</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">ApiInfoBuilder</span>()</span><br><span class="line">                .title(<span class="string">&quot;苍穹外卖项目接口文档&quot;</span>)</span><br><span class="line">                .version(<span class="string">&quot;2.0&quot;</span>)</span><br><span class="line">                .description(<span class="string">&quot;苍穹外卖项目接口文档&quot;</span>)</span><br><span class="line">                .build();</span><br><span class="line">        <span class="type">Docket</span> <span class="variable">docket</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Docket</span>(DocumentationType.SWAGGER_2)</span><br><span class="line">                .apiInfo(apiInfo)</span><br><span class="line">                .select()</span><br><span class="line">                .apis(RequestHandlerSelectors.basePackage(<span class="string">&quot;com.sky.controller&quot;</span>))</span><br><span class="line">                .paths(PathSelectors.any())</span><br><span class="line">                .build();</span><br><span class="line">        <span class="keyword">return</span> docket;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>


</li>
<li><p>设置静态资源映射，否则接口文档页面无法访问</p>
<p>WebMvcConfiguration.java</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 设置静态资源映射</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> registry</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title function_">addResourceHandlers</span><span class="params">(ResourceHandlerRegistry registry)</span> &#123;</span><br><span class="line">        registry.addResourceHandler(<span class="string">&quot;/doc.html&quot;</span>).addResourceLocations(<span class="string">&quot;classpath:/META-INF/resources/&quot;</span>);</span><br><span class="line">        registry.addResourceHandler(<span class="string">&quot;/webjars/**&quot;</span>).addResourceLocations(<span class="string">&quot;classpath:/META-INF/resources/webjars/&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
</ol>
<p>4.访问测试</p>
<p>接口文档访问路径为 <a href="http://ip:port/doc.html">http://ip:port/doc.html</a> —&gt; <a target="_blank" rel="noopener" href="http://localhost:8080/doc.html">http://localhost:8080/doc.html</a></p>
<p><strong>思考：</strong>通过 Swagger 就可以生成接口文档，那么我们就不需要 Yapi 了？</p>
<p>1、Yapi 是设计阶段使用的工具，管理和维护接口</p>
<p>2、Swagger 在开发阶段使用的框架，帮助后端开发人员做后端的接口测试</p>
<p>5.通过注解可以控制生成的接口文档，使接口文档拥有更好的可读性，常用注解如下：</p>
<table>
<thead>
<tr>
<th><strong>注解</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>@Api</td>
<td>用在类上，例如Controller，表示对类的说明</td>
</tr>
<tr>
<td>@ApiModel</td>
<td>用在类上，例如entity、DTO、VO</td>
</tr>
<tr>
<td>@ApiModelProperty</td>
<td>用在属性上，描述属性信息</td>
</tr>
<tr>
<td>@ApiOperation</td>
<td>用在方法上，例如Controller的方法，说明方法的用途、作用</td>
</tr>
</tbody></table>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>Author: </span><span class="post-copyright-info"><a href="https://t0wolf.gitee.io/xiaopanblog">John Doe</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>Link: </span><span class="post-copyright-info"><a href="https://t0wolf.gitee.io/xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/">https://t0wolf.gitee.io/xiaopanblog/2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="./2023/11/01/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day2/" title="苍穹外卖笔记day2"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous</div><div class="prev_info">苍穹外卖笔记day2</div></div></a></div><div class="next-post pull-right"><a href="./2023/10/31/Spring%E7%AC%94%E8%AE%B0/" title="Spring笔记"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next</div><div class="next_info">Spring笔记</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='./img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">John Doe</div><div class="author-info__description">一个简单的个人博客</div></div><div class="card-info-data site-data is-center"><a href="./archives/"><div class="headline">Articles</div><div class="length-num">10</div></a><a href="./tags/"><div class="headline">Tags</div><div class="length-num">1</div></a><a href="./categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Contents</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96-day01"><span class="toc-number">1.</span> <span class="toc-text">苍穹外卖-day01</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E4%BA%94%E5%A4%A7%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B"><span class="toc-number">1.1.</span> <span class="toc-text">1.五大技术选型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.2.</span> <span class="toc-text">2. 开发环境搭建</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-%E5%89%8D%E7%AB%AF%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.2.1.</span> <span class="toc-text">1. 前端环境搭建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-%E5%90%8E%E7%AB%AF%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.2.2.</span> <span class="toc-text">2.后端环境搭建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-%E6%95%B0%E6%8D%AE%E5%BA%93%E6%90%AD%E5%BB%BA"><span class="toc-number">1.2.3.</span> <span class="toc-text">3.数据库搭建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-%E5%89%8D%E5%90%8E%E7%AB%AF%E8%81%94%E8%B0%83"><span class="toc-number">1.2.4.</span> <span class="toc-text">4. 前后端联调</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-nginx"><span class="toc-number">1.3.</span> <span class="toc-text">3.nginx</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-nginx%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86"><span class="toc-number">1.3.1.</span> <span class="toc-text">1.nginx反向代理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-nginx-%E8%B4%9F%E8%BD%BD%E5%9D%87%E8%A1%A1%E7%AD%96%E7%95%A5"><span class="toc-number">1.3.2.</span> <span class="toc-text">2.nginx 负载均衡策略</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-%E5%AE%8C%E5%96%84%E7%99%BB%E5%BD%95%E5%8A%9F%E8%83%BD"><span class="toc-number">1.4.</span> <span class="toc-text">4.完善登录功能</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-%E5%AF%BC%E5%85%A5%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3"><span class="toc-number">1.5.</span> <span class="toc-text">5. 导入接口文档</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E6%AD%A5%E9%AA%A4"><span class="toc-number">1.5.1.</span> <span class="toc-text">使用步骤</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="./2023/11/25/markdown%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0/" title="markdown学习笔记">markdown学习笔记</a><time datetime="2023-11-25T06:47:13.000Z" title="Created 2023-11-25 14:47:13">2023-11-25</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="./2023/11/06/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day3/" title="苍穹外卖笔记day3">苍穹外卖笔记day3</a><time datetime="2023-11-06T01:36:00.000Z" title="Created 2023-11-06 09:36:00">2023-11-06</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="./2023/11/01/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day2/" title="苍穹外卖笔记day2">苍穹外卖笔记day2</a><time datetime="2023-11-01T13:05:25.000Z" title="Created 2023-11-01 21:05:25">2023-11-01</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="./2023/10/31/%E8%8B%8D%E7%A9%B9%E5%A4%96%E5%8D%96%E7%AC%94%E8%AE%B0day1/" title="苍穹外卖笔记day1">苍穹外卖笔记day1</a><time datetime="2023-10-31T09:13:57.000Z" title="Created 2023-10-31 17:13:57">2023-10-31</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="./2023/10/31/Spring%E7%AC%94%E8%AE%B0/" title="Spring笔记">Spring笔记</a><time datetime="2023-10-31T03:08:11.000Z" title="Created 2023-10-31 11:08:11">2023-10-31</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By John Doe</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Toggle Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between Single-column and Double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="./js/utils.js"></script><script src="./js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>